const joi = require('joi');
const moment = require('moment');
const dateFormat = 'YYYY-MM-DD HH:mm:ss';
const title = joi.string()
  .required();
const startTime = joi.date()
  .custom((value, helpers) => {
    if (!moment(value, dateFormat, true).isValid()) {
      return helpers.error('any.invalid', { value });
    }
    return moment(value, dateFormat).toDate();
  })
  .required();
const endTime = joi.date()
  .custom((value, helpers) => {
    if (!moment(value, dateFormat, true).isValid()) {
      return helpers.error('any.invalid', { value });
    }
    return moment(value, dateFormat).toDate();
  }).required().greater(joi.ref('startTime')).label('结束时间');
const description = joi.string();


exports.add_schedule_schema = {
  body: {
    title,
    startTime,
    endTime,
    description
  }
};
